﻿using FluentValidation;
using FluentValidation.Results;
using System.Collections;

namespace RayD.WebApi.Models.Interact
{
    /// <summary>
    /// 业务参数基类
    /// </summary>
    public abstract class BaseModel
    {
        /// <summary>
        /// 业务参数验证
        /// </summary>
        /// <returns></returns>
        public abstract (bool, string) CheckParameter();

        /// <summary>
        /// 业务参数验证
        /// </summary>
        /// <param name="validation">FluentValidation验证返回结果</param>
        /// <returns></returns>
        public (bool, string) CheckParameter(ValidationResult validation)
        {
            if (!validation.IsValid)
            {
                // 返回第一个错误信息
                return (false, validation.Errors[0].ErrorMessage);
            }
            return (true, "验证成功！");
        }
    }
}
